/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.zx.ObjectClasses;

import java.util.ArrayList;
import java.util.Comparator;

/**
 *
 * @author VcLi
 */
public class TrainService implements Comparable<TrainService> {

    private ArrayList<Station> stnList = new ArrayList<Station>();
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    
    public ArrayList<Station> getStnList() {
        return stnList;
    }

    public void setStnList(ArrayList<Station> stnList) {
        this.stnList = stnList;
    }

    public int getStationNumber(Station s){
        for(int i=0; i<stnList.size(); i++){
            if(stnList.get(i).getName().equals(s.getName())){
                return i;
            }
        }
        return 0;
    }

    public void reverseStationList(){
        ArrayList<Station> alStn = new ArrayList<Station>();
        alStn = stnList;
        stnList = new ArrayList<Station>();
        for(int i=alStn.size()-1; i>=0; i--){
            stnList.add(alStn.get(i));
        }
    }
    
    public static Comparator<TrainService> trainnameComparator = new Comparator<TrainService>() {

        public int compare(TrainService trainService1, TrainService trainService2) {

            String trainname1 = trainService1.getName().toUpperCase();
            String trainname2 = trainService2.getName().toUpperCase();

            //ascending order
            return trainname1.compareTo(trainname2);

            //descending order
            //return trainname2.compareTo(trainname1);
        }
    };

    @Override
    public int compareTo(TrainService ts) {
        return name.compareTo(ts.getName());
    }
}
